
import { 
  LineSegments,
  PerspectiveCamera, 
  Scene, 
  SphereBufferGeometry, 
  WebGLRenderer, 
  WireframeGeometry 
} from 'three'
import stats from '../../utils/stats'
import { TrackballControls } from 'three/examples/jsm/controls/TrackballControls'
import dat from 'dat.gui'

const scene = new Scene()
const camera = new PerspectiveCamera(45, window.innerWidth/window.innerHeight, 0.1, 1000)
camera.position.set(0, 0, 100)
camera.lookAt(0, 0, 0)

// 生成要渲染的几何图形
const shpereGeometry = new SphereBufferGeometry(10, 20, 20)
// 添加网格几何体
const shpereWireframe = new WireframeGeometry(shpereGeometry)
// 生成线
const line = new LineSegments( shpereWireframe )
scene.add(line)

const renderer = new WebGLRenderer({ antialias: true })
renderer.setPixelRatio(window.devicePixelRatio)
renderer.setSize(window.innerWidth, window.innerHeight)
renderer.setClearColor(0x000000)

document.body.appendChild(renderer.domElement)
const trackballControls = new TrackballControls(camera, renderer.domElement)

function render() {
  stats.update()
  trackballControls.update()

  line.rotation.y += 0.01

  requestAnimationFrame(render)
  renderer.render(scene, camera)
}

render()